package com.thb.base.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.thb.base.service.IVersionService;
import com.thb.logs.utils.LogUtils;
import com.thb.utils.ResponseTool;

@Controller
public class VersionController {
	
	private static final Logger logger = LogUtils.getBaseLog();
	
	@Autowired
	private IVersionService versionService;
	
	@RequestMapping(value = "/version/check" , method = RequestMethod.POST)
	@ResponseBody
	public Object add(HttpServletRequest request){
		String json = request.getParameter("args");
		logger.info(String.format("args is: %s", json));
		JSONObject o = JSONObject.parseObject(json);
		String version = o.getString("version");
		JSONObject object = new JSONObject(); 
		if(StringUtils.isNotEmpty(version)&& StringUtils.isNumeric(version)){
			object = versionService.checkVersion(Integer.valueOf(version));
		}
		
		return ResponseTool.returns(object);
	}
	
}
